/*
 * Copyright (c) 2011 University of Tartu
 */
package org.qsardb.visitor;

import org.qsardb.model.*;

abstract
public class Visitor {

	transient
	private Storage storage = null;

	transient
	private Qdb qdb = null;


	public void begin() throws Exception {
	}

	final
	public void accept(Storage storage) throws Exception {
		setStorage(storage);

		try {
			visit(storage);
		} finally {
			setStorage(null);
		}
	}

	public void visit(Storage storage) throws Exception {
		Qdb qdb = new Qdb(storage);

		try {
			accept(qdb);
		} finally {
			qdb.close();
		}
	}

	final
	public void accept(Qdb qdb) throws Exception {
		setQdb(qdb);

		try {
			visit(qdb);
		} finally {
			setQdb(null);
		}
	}

	public void visit(Qdb qdb) throws Exception {
	}

	public void end() throws Exception {
	}

	public Storage getStorage(){
		return this.storage;
	}

	private void setStorage(Storage storage){
		this.storage = storage;
	}

	public Qdb getQdb(){
		return this.qdb;
	}

	private void setQdb(Qdb qdb){
		this.qdb = qdb;
	}
}